﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Threading;
using MobileBroadbandUserBlog.MBLM.Core.Interfaces;
using MobileBroadbandUserBlog.MBLM.Core.MobileSoftware;


namespace MobileBroadbandUserBlog.MBLM
{
    public class MobileSoftwareFactory : IMobileSoftwareFactory
    {
        private List<IMobileSoftware> _mobileSoftwares;
        #region IMobileSoftwareFactory Members

        public override ReadOnlyCollection<IMobileSoftware> GetMobileBroadbandSoftware()
        {
            EnsureCollection();
            ReadOnlyCollection<IMobileSoftware> result = new ReadOnlyCollection<IMobileSoftware>(_mobileSoftwares);
            return result;
        }

        private void EnsureCollection()
        {
            if (_mobileSoftwares == null)
            {
                _mobileSoftwares = new List<IMobileSoftware>();
                InitializeMobileBroadbandSoftwareCollection();
            }
        }

        public override void AddMobileBroadbandSoftware(IMobileSoftware mobileSoftware)
        {
            if (mobileSoftware == null)
            {
                throw new ArgumentNullException("mobileSoftware cannot be null.");
            }
            EnsureCollection();
            _mobileSoftwares.Add(mobileSoftware);
        }

        public override void RemoveMobileBroadbandSoftware(IMobileSoftware mobileSoftware)
        {
            if (mobileSoftware == null)
            {
                throw new ArgumentNullException("mobileSoftware cannot be null.");
            }

            EnsureCollection();
            if (_mobileSoftwares.Contains(mobileSoftware))
            {
                _mobileSoftwares.Remove(mobileSoftware);
            }
        }

        protected virtual void InitializeMobileBroadbandSoftwareCollection()
        {
            AddMobileBroadbandSoftware(new BirdStepTechnologyEasyConnectOld());
            AddMobileBroadbandSoftware(new BirdStepTechnologyEasyConnectNew());
            AddMobileBroadbandSoftware(new HUAWEIMobilePartner());
            AddMobileBroadbandSoftware(new MWConnSoftware());
        }

       

        #endregion
    }
}
